<template>
  <div>
    <div>修改界面</div>
    <div> New Cate:<input type="text" v-model="cate">
      <input type="button" @click="updcate" value="修改分类"></div>
  </div>
</template>

<script>
  export default {
    name: "Upd",
    data: function () {
      return {
        cate: '',
        id: this.$route.params.id
      }
    },
    methods: {
      updcate() {
        this.axios({
          url: 'http://localhost:8000/myapp/cate/',
          method: 'post',
          data: {'id': this.id, 'newname': this.cate}
        }).then(res => {
          console.log(res.data);
          this.$router.push({name: 'Index'})
        })
      },
      getcate() {
        this.axios({
          url: `http://localhost:8000/myapp/cate/?id=` + this.id,
          method: 'get',
        }).then(res => {
          console.log(res.data);
          this.cate = res.data.data.name
        })
      }
    },
    mounted() {
      this.getcate()
    }
  }
</script>

<style scoped>

</style>
